﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace kwzx.Common
{
    public static class CallUserProc
    {


        private static string _scmPhotoPath = System.Configuration.ConfigurationSettings.AppSettings["scmPhotoAdd"]; //配置文件读取  scm图片路径
        private static string _platPhotoPath = "";   //配置文件读取  平台ftp路径

        /// <summary>
        /// 人员信息CU调用存储过程
        /// 调用此方法需要确保 姓名+身份证号的图片在图片文件夹中存在且唯一
        /// </summary>
        /// <param name="userID">人员编号  在web平台唯一 不允许重复</param>
        /// <param name="userName">姓名  web平台正式姓名</param>
        /// <param name="user_identity">身份证号</param>
        /// <param name="sex">性别</param>
        /// <param name="dept_ID">人员所在部门</param>
        public static void AddUserProc(string userID, string userName, string user_identity, string sex, string dept_ID, string platPath)
        {
            string imgName = userName + user_identity + ".jpg";
            string platName = platPath + imgName;
            string photoName = "";
            CallProc call = new CallProc();
            if (File.Exists(platName))
            {
                photoName = call.UserEx(userID, userName, 1, sex, user_identity, 0, dept_ID);

                if (!string.IsNullOrWhiteSpace(photoName))
                {
                    //scm平台照片存放文件夹命名方式为人员序号除以1000
                    int folderName = int.Parse(photoName.Substring(0, photoName.Length - 4)) / 1000;
                    if (!Directory.Exists(_scmPhotoPath + folderName))
                    {
                        Directory.CreateDirectory(_scmPhotoPath + folderName);
                    }
                    string scmphotoName = _scmPhotoPath + folderName + "\\" + photoName;

                    //裁减图片原图片为平台原始图片,保存在scm平台根目录,因后面要压缩 故没有放在对应文件夹中
                    imgUtils.CutForCustom(platPath + imgName, _scmPhotoPath + imgName, 140, 194, 0);
                    //压缩图片  原图片在scm平台图片根目录,压缩后图片在人员序号/1000的文件夹中，长,宽，质量
                    Common.CommonImg.CompressImage(_scmPhotoPath + imgName, scmphotoName, 194, 140, 60);
                    //imgUtils.GetReducedImage(exportPath + imgName, scmphotoName, 140, 194, 0);

                    //删除在scm平台图片根目录的图片
                    File.Delete(_scmPhotoPath + imgName);



                }
            }
            else
            {
                photoName = call.UserEx(userID, userName, 0, sex, user_identity, 0, dept_ID);
            }

        }
    }
}
